<?php if (!defined('ITPK')) exit('You can not directly access the file.');

/**
 * 群成员操作类
 * @author 冬天的秘密
 * @link http://bbs.itpk.cn
 * @version 1.0
 */

class WebgroupmemberPer extends WebDBConnection {

	/**
	 * 根据群成员ID获取资料
	 * @param id $group_member_id
	 * @return array | boolean
	 */
	public function getMeById($group_member_id) {
		return $this->db->executeQuery("SELECT * FROM web_group_member where id = {$group_member_id}", true);
	}

	/**
	 * 根据群号和群成员账号获取资料
	 * @param string $uin
	 * @param string $group_uin
	 * @param string $member_uin
	 * @return array | boolean
	 */
	public function getMe($uin, $group_uin, $member_uin) {
		return $this->db->executeQuery("SELECT * FROM web_group_member where uin = '{$uin}' and group_uin = '{$group_uin}' and member_uin = '{$member_uin}'", true);
	}

	/**
	 * 新增群成员记录
	 * @param string $uin
	 * @param string $group_uin
	 * @param string $member_uin
	 * @param string $nick_name
	 * @param int $is_reply
	 */
	public function insertMe($uin, $group_uin, $member_uin, $nick_name = "") {
		return $this->db->executeQuery("INSERT INTO web_group_member(uin, group_uin, member_uin, nick_name, createdate) VALUES('{$uin}', '{$group_uin}', '{$member_uin}', '{$nick_name}', " . time() . ")");
	}

	/**
	 * 扣除或增加群成员的金币
	 * @param int $group_member_id
	 * @param int $gold
	 * @param boolean $is_add 是否为增加，默认为false
	 * @return int | boolean
	 */
	public function updateGold($group_member_id, $gold, $is_add = false) {
		$symbol = $is_add ? "+" : "-";
		return $this->db->executeQuery("UPDATE web_group_member SET gold = gold {$symbol} {$gold} WHERE id = {$group_member_id}");
	}

	/**
	 * 扣除或增加群成员的经验
	 * @param int $group_member_id
	 * @param int $experience
	 * @param boolean $is_add 是否为增加，默认为false
	 * @return int | boolean
	 */
	public function updateExperience($group_member_id, $experience, $is_add = false) {
		$symbol = $is_add ? "+" : "-";
		return $this->db->executeQuery("UPDATE web_group_member SET experience = experience {$symbol} {$experience} WHERE id = {$group_member_id}");
	}

	/**
	 * 根据群成员ID删除群成员信息
	 * @param int $group_member_id
	 */
	public function deleteMe($group_member_id) {
		return $this->db->executeQuery("DELETE FROM web_group_member WHERE id = {$group_member_id}");
	}

	/**
	 * 更新机器人插件定位
	 * @param int $group_member_id
	 * @param int $plugin_id
	 * @return Ambigous <multitype:, boolean>
	 */
	public function updatePluginId($group_member_id, $plugin_id) {
		return $this->db->executeQuery("UPDATE web_group_member SET plugin_id = {$plugin_id} WHERE id = '{$group_member_id}'");
	}

}
?>